package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Order;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Name OrderController
 * @Author stella
 * @Date 2023-03-09 4:59 PM
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 下订单新增订单
     * @param order
     * @return
     */
    @PostMapping("/submit")
    public ResultInfo addOrder(@RequestBody  Order order){
        orderService.addOrder(order);
        return ResultInfo.success();
    }

    /**
     * 历史订单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public ResultInfo orderPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        Page<Order> orderPage = orderService.orderPage(page,pageSize);
        return ResultInfo.success(orderPage);
    }
}
